import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { UserService } from '../../services/user.service';
import { User } from '../../entity/User';
import { Route } from '@angular/compiler/src/core';
import { Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-taoti',
  templateUrl: './taoti.component.html',
  styleUrls: ['./taoti.component.css']
})
export class TaotiComponent implements OnInit {
  data = [];
  constructor(private http: HttpClient
    , private router: Router
    , private message: NzMessageService) {
  }

  ngOnInit() {
    this.Search();
  }

  Search() {
    this.http
      .get(`/api/TaoTi/all`)
      .subscribe(response => {
        this.data = response as Array<any>;
      });
  }

  New() {
    this.router.navigate(['content/alterTaoti/0']);
  }

  Alter(id) {
    this.router.navigate([`content/alterTaoti/${id}`]);
  }

  Delete(id) {
    this.http
      .get(
        `/api/TaoTi/delete?id=${id}`
      ).subscribe(response => {
        this.message.info('删除成功');
        this.Search();
      });
  }
}
